package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import pojo.Customer;
import util.DBUtil;
import dao.CustomerDao;

public class CustomerDaoImpl implements CustomerDao {

	@Override
	public Customer load(String cname) {
		String sql = "select * from customers where cname=?";
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		Customer c = null;
		
		try {
			conn = DBUtil.createConnection();
			pst = conn.prepareStatement(sql);
			pst.setString(1, cname);
			
			rs = pst.executeQuery();
			if (rs.next()) {
				c = new Customer(rs.getString("id"), rs.getString("cname"), rs.getString("passwd"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(conn, pst, null);
		}
		return c;
	}

}
